/**
 * 上海中赢金融信息服务有限公司
 * Copyright (c) 2017-2027 Chinazyjr,Inc.All Rights Reserved.
 */

package com.sys.midware.mongo.core.mongoOP;

import java.util.LinkedHashMap;
import java.util.Map;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * <b>ClassName:</b> MongoSort1.java <br/>
 * <b>Description:</b> TODO <br/>
 * <b>Date:</b>     2016年1月13日 下午1:14:12<br/> 
 * @author   mobing
 * @version  	 
 */
public class MongoSort {
    /**
     * mongo排序类
     */
    public static enum MongoOrder {
        ASC, DESC  
    }
    
    /** key为排序的名称, value为顺序 */  
    private Map<String, MongoOrder> field = new LinkedHashMap<String, MongoOrder>();  
  
    public MongoSort() {  
    }  
  
    public MongoSort(String key, MongoOrder order) {  
        field.put(key, order);  
    }  
  
    public MongoSort on(String key, MongoOrder order) {  
        field.put(key, order);  
        return this;  
    }  
  
    public DBObject getSortObject() {  
        DBObject dbo = new BasicDBObject();  
        for (String k : field.keySet()) {  
            dbo.put(k, (field.get(k).equals(MongoOrder.ASC) ? 1 : -1));  
        }  
        return dbo;  
    }  
}

